/* name: string
 * author: 5ab
 * created at: 2024-06-15
 */
#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define ssz(x) (int((x).size()))

auto chmax = [](auto& x, auto y) { if (x < y) x = y; };
auto chmin = [](auto& x, auto y) { if (y < x) x = y; };

using ll = long long;
const int N = 1e6, C = 26;

char ss[N + 1];
int sa[N], rk[N], d[N * 2], fp[N], fs[N], f[N], nxt[N + 1];

bool solve()
{
	int n;
	
	cin >> n;
	fill(rk, rk + n, -1);
	for (int i = 0; i < n; i++)
		cin >> sa[i];
	for (int i = 0; i < n * 2 - 1; i++)
		cin >> d[i];
	for (int i = 0; i < n; i++)
	{
		if (sa[i] < 0 || sa[i] >= n || rk[sa[i]] != -1)
			return 0;
		rk[sa[i]] = i;
	}
	iota(fs, fs + n, 0);
	fill(fp, fp + n, -1);
	
	auto ads = [&](int x, int y)
	{
		x = rk[x], y = rk[y];
		if (x > y) swap(x, y);
		chmin(fs[y], x);
	};
	auto adp = [&](int x, int y)
	{
		x = rk[x], y = rk[y];
		if (x > y) swap(x, y);
		chmax(fp[y], x);
	};
	
	// int gc = 0;
	for (int i = 0; i < n * 2 - 1; i++)
	{
		if (i + d[i] > 2 * n || d[i] > i + 1 || (d[i] & 1) == (i & 1))
			return 0;
		// cerr << i << " " << d[i] << endl;
		// gc += d[i];
		for (int j = d[i]; j >= 2; j -= 2)
			ads((i + j) / 2, (i - j + 1) / 2);
		if (i + d[i] < 2 * n - 1 && d[i] < i)
			adp((i + d[i]) / 2 + 1, (i - d[i]) / 2);
	}
	// cerr << gc << endl;
	for (int i = 1; i < n; i++)
		if (sa[i - 1] != n - 1 && (sa[i] == n - 1 || rk[sa[i - 1] + 1] > rk[sa[i] + 1]))
			fp[i] = i - 1;
	int cl = n - 1, ls = n;
	vector<int> gp = { n };
	for (int i = n - 1; i >= 0; i--)
	{
		chmin(cl, fs[i]);
		if (cl == i)
		{
			for (int j = cl; j < ls; j++)
			{
				fs[j] = cl;
				if (fp[j] >= cl)
					return 0;
				if (j != cl)
					chmax(fp[j], fp[j - 1]);
			}
			gp.push_back(cl);
			// cerr << cl << " " << ls << endl;
			cl = i - 1, ls = i;
		}
	}
	reverse(all(gp));
	nxt[n] = n;
	// cerr << n << " " << nxt[n] << endl;
	for (int i = n - 1; i >= 0; i--)
	{
		if (fs[i] == i)
			nxt[i] = i;
		else
			nxt[i] = nxt[i + 1];
		// cerr << i << " " << nxt[i] << " " << nxt[i + 1] << endl;
	}
	vector<int> stk;
	for (int x : gp)
	{
		while (!stk.empty() && fp[x] <= fp[stk.back()])
			chmax(fp[x], fp[stk.back()]), stk.pop_back();
		stk.push_back(x);
	}
	f[0] = 0;
	for (int i : gp) if (i != 0)
	{
		f[i] = f[nxt[fp[i - 1] + 1]] + 1;
		// cerr << i << "  " << fp[i] << " " << nxt[fp[i - 1] + 1] << " " << f[i] << endl;
	}
	if (f[n] > C)
		return 0;
	for (int x = n, y = n - 1; y >= 0; y--)
	{
		ss[sa[y]] = f[x] + 'a' - 1;
		if (fs[y] == y)
			x = y;
	}
	ss[n] = 0;
	cout << ss << "\n";
	return 1;
}

signed main()
{
	freopen("string.in", "r", stdin);
	freopen("string.out", "w", stdout);
	
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int cas;
	
	cin >> cas;
	while (cas--)
	{
		if (!solve())
			cout << "-1\n";
	}
	
	return 0;
}
// started coding at: 06-15 10:56:22